package com.augurit.gzcgwsp.sendNotice.service.impl;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.augurit.common.syslog.tool.SysTraceLogWriter;
import com.augurit.common.system.service.org.IOmUserService;
import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.system.web.org.form.OmUserForm;
import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.csshlj.convert.YwHwCzConvertor;
import com.augurit.gzcgwsp.csshlj.convert.YwHwShljysConvertor;
import com.augurit.gzcgwsp.csshlj.form.ShljYsForm;
import com.augurit.gzcgwsp.csshlj.service.ICsshljCzService;
import com.augurit.gzcgwsp.csshlj.service.IShljYsService;
import com.augurit.gzcgwsp.csshlj.web.form.CsshljCzForm;
import com.augurit.gzcgwsp.hwgz.convert.YwHwShSqbConvertor;
import com.augurit.gzcgwsp.hwgz.service.IYwHwShSqbService;
import com.augurit.gzcgwsp.hwgz.web.form.YwHwShSqbForm;
import com.augurit.gzcgwsp.jzfqwczz.convert.YwYnJzfqwczcJbxxConvertor;
import com.augurit.gzcgwsp.jzfqwczz.service.IYwYnJzfqwczcBghzService;
import com.augurit.gzcgwsp.jzfqwczz.service.IYwYnJzfqwczcJbxxService;
import com.augurit.gzcgwsp.jzfqwczz.service.IYwYnJzfqwczcNsxzService;
import com.augurit.gzcgwsp.jzfqwczz.service.IYwYnJzfqwczcShhzService;
import com.augurit.gzcgwsp.jzfqwczz.service.IYwYnJzfqwczcYsbbService;
import com.augurit.gzcgwsp.jzfqwczz.web.form.YwYnJzfqwczcJbxxForm;
import com.augurit.gzcgwsp.jzfqwczzpfsn.convert.YwYnJzfqwczzPfsnConvert;
import com.augurit.gzcgwsp.jzfqwczzpfsn.service.IYwYnJzfqwczzPfsnService;
import com.augurit.gzcgwsp.jzfqwczzpfsn.service.IYwYnJzfqwczzPfsnbgService;
import com.augurit.gzcgwsp.jzfqwczzpfsn.service.IYwYnJzfqwczzPfsnyqService;
import com.augurit.gzcgwsp.jzfqwczzpfsn.web.form.YwYnJzfqwczzPfsnForm;
import com.augurit.gzcgwsp.jzfqwczzxn.convert.YwYnJzfqwczzXnConvert;
import com.augurit.gzcgwsp.jzfqwczzxn.service.IYwYnJzfqwczzXnService;
import com.augurit.gzcgwsp.jzfqwczzxn.service.IYwYnJzfqwczzXnbgService;
import com.augurit.gzcgwsp.jzfqwczzxn.service.IYwYnJzfqwczzXnyqService;
import com.augurit.gzcgwsp.jzfqwczzxn.web.form.YwYnJzfqwczzXnForm;
import com.augurit.gzcgwsp.qyzz.convert.YwRqQyzzInfoConvertor;
import com.augurit.gzcgwsp.qyzz.service.IYwRqQyzzInfoService;
import com.augurit.gzcgwsp.qyzz.web.form.YwRqQyzzInfoForm;
import com.augurit.gzcgwsp.rqqyjyxk.convert.YwRqQyjyxkConvertor;
import com.augurit.gzcgwsp.rqqyjyxk.service.IYwRqQyjyxkService;
import com.augurit.gzcgwsp.rqqyjyxk.web.form.YwRqQyjyxkForm;
import com.augurit.gzcgwsp.sendNotice.entity.YwClosecase;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.CsshljczForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.ShljYsForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwGgcsForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwHwShSqbForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwHwShljqsForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwRqQyjyxkForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwRqQyzzInfoForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwRqSsgdSqbForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwSrCsdlwjForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwSrDlzyForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwYnJzfqwczcJbxxForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwYnJzfqwczzPfsnForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwYnJzfqwczzXnForFx;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.util.Object2XML;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.util.UnitValue;
import com.augurit.gzcgwsp.sendNotice.service.IExchangeStateService;
import com.augurit.gzcgwsp.sendNotice.service.IYwClosecaseService;
import com.augurit.gzcgwsp.sendNotice.service.IYwSphjInfoService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceInfoService;
import com.augurit.gzcgwsp.sendNotice.service.IYwZhengwuInfoService;
import com.augurit.gzcgwsp.smartformCsdlwj.convert.YwHwShljqsConvertor;
import com.augurit.gzcgwsp.smartformCsdlwj.convert.YwSrCsdlwjConvertor;
import com.augurit.gzcgwsp.smartformCsdlwj.convert.YwSrDlzyConvertor;
import com.augurit.gzcgwsp.smartformCsdlwj.convert.YwSrGgcsConvertor;
import com.augurit.gzcgwsp.smartformCsdlwj.service.ISmartFormShljqsService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwCsdlwjService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwDlzyService;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwGgcsServices;
import com.augurit.gzcgwsp.smartformCsdlwj.service.IYwShljqsService;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.CsdlwjForm;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.DlzyForm;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.GgcsForm;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.ShljqsForm;
import com.augurit.gzcgwsp.ssgd.convert.YwRqSsgdSqbConvertor;
import com.augurit.gzcgwsp.ssgd.service.IYwRqSsgdSqbService;
import com.augurit.gzcgwsp.ssgd.web.form.YwRqSsgdSqbForm;
import com.augurit.gzcgwsp.wfex.common.dao.Jbpm4HistTaskDaoEX;
import com.augurit.gzcgwsp.wfex.common.service.IWfServiceEX;
import com.augurit.gzcgwsp.wfex.common.util.WfUtilsEX;
import com.augurit.gzcgwsp.ywcmn.entity.YwComFsxx;
import com.augurit.gzcgwsp.ywcmn.service.IYwComFsxxService;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.common.dao.Jbpm4HistProcinstDao;
import com.augurit.wf.common.dao.Jbpm4HistTaskDao;
import com.augurit.wf.common.entity.Jbpm4HistProcinst;
import com.augurit.wf.common.entity.Jbpm4HistTask;
/**
 * 交换案件状态
 * @author      ...     ...      ...
 *
 */

@Service
@Transactional
public class ExchangeStateServiceImpl implements IExchangeStateService{
	private static final Logger logger = Logger.getLogger(ExchangeStateServiceImpl.class);	 
	@Autowired
	private IWfServiceEX wfServiceEX;	
	@Autowired
	private IYwRqSsgdSqbService ywRqSsgdSqbService;	
	@Autowired
	private IYwRqQyzzInfoService ywRqQyzzInfoService;	
	@Autowired
	private IYwHwShSqbService ywHwShSqbService;	
	@Autowired
	private IYwWebserviceInfoService ywWebserviceInfoService;	
	@Autowired
	private IYwRqQyjyxkService ywRqQyjyxkService;	
	@Autowired
	private Jbpm4HistTaskDao jbpm4HistTaskDao;	
	@Autowired
	private Jbpm4HistTaskDaoEX jbpm4HistTaskDaoEX;	
	@Autowired
	private IYwZhengwuInfoService ywZhengwuInfoService;	
	@Autowired
	private IYwComFsxxService ywComFsxxService;	
	@Autowired
	private IOmUserService omUserService;	
	@Autowired
	private IYwSphjInfoService ywSphjInfoService;
	@Autowired
	private IYwClosecaseService ywClosecaseService;	
	@Autowired
	private IYwDlzyService ywDlzyService;	
	@Autowired
	private IYwGgcsServices ywGgcsServices;	
	@Autowired
	private IYwCsdlwjService ywCsdlwjService;    
    @Autowired
    private IYwShljqsService ywShljqsService;
    @Autowired
    private ISmartFormShljqsService smartFormShljqsService;
    @Autowired
    private IShljYsService shljYsService;    
    @Autowired
    private ICsshljCzService csshljCzService;    
    @Autowired
    private IYwYnJzfqwczzPfsnService ywYnJzfqwczzPfsnService;    
    @Autowired
    private IYwYnJzfqwczzPfsnyqService ywYnJzfqwczzPfsnyqService;    
    @Autowired
    private IYwYnJzfqwczzPfsnbgService ywYnJzfqwczzPfsnbgService;    
    @Autowired
    private IYwYnJzfqwczzXnService ywYnJzfqwczzXnService;    
    @Autowired
    private IYwYnJzfqwczzXnbgService ywYnJzfqwczzXnbgService;    
    @Autowired
    private IYwYnJzfqwczzXnyqService ywYnJzfqwczzXnyqService;
    @Autowired
    private IYwYnJzfqwczcBghzService ywYnJzfqwczcBghzService;
    @Autowired
    private IYwYnJzfqwczcJbxxService ywYnJzfqwczcJbxxService;
    @Autowired
    private IYwYnJzfqwczcNsxzService ywYnJzfqwczcNsxzService;
    @Autowired
    private IYwYnJzfqwczcShhzService ywYnJzfqwczcShhzService;
    @Autowired
    private IYwYnJzfqwczcYsbbService ywYnJzfqwczcYsbbService;
	@Autowired
	private Jbpm4HistProcinstDao jbpm4HistProcinstDao;
    private String sprzwdm ="";
    private String sprzwmc ="";
	/**
	 * 案件状态交换
	 * @param user
	 * @param instance
	 */
	public void exchangeState(LoginUserForm user,WfBusInstanceTaskForm instance) throws Exception{
		//读取接口配置信息
		Locale locale = Locale.getDefault(); 
		ResourceBundle localResource = ResourceBundle.getBundle("interfaceExchange", locale); 
		Long taskInstDbid = instance.getTaskInstDbid();
		
		//获得时间表达式  格式为 ：26 business days
		String durationExpression = wfServiceEX.getProcDueExpressIonByTaskInstDbid(taskInstDbid);
		
		Jbpm4HistTask thisInstance = jbpm4HistTaskDao.get(taskInstDbid);//这个节点对象
//		String thisNoteActivityName = wfTaskSummary.getActivityName();//这个节点的英文名称
		String thisNoteActivityName = thisInstance.getActivityName();//这个节点的英文名称
		String nextNoteActivityName = instance.getDestActivityName();//下个节点的英文名称
		String loginUserName = user.getUser().getUserName();
		getLdClass(thisNoteActivityName);
		String dpm = user.getOrg().getOrgName();
		//获得ID
		String masterEntityKey = instance.getMasterEntityKey();
		String templateCode = instance.getTemplateCode();
		Date acceptTime = getAcceptTime(thisInstance);
		if(StringUtils.isNotEmpty(masterEntityKey)){	
	    	String serialNo = "";
	    	String password = "";
	    	String sxbm = wfServiceEX.getPropertiesValueByKey(localResource, templateCode);
	    	String cbyw = "";
	    	String sqrhsqdw =  "";
	    	String lxdh = "";
	    	String lxr = "";
	    	String sendNotice = "";
	    	Date wstjsj = null;
	    	Map<String,String> map=this.buildMap(user, taskInstDbid, masterEntityKey, templateCode, false);
			map.put("sxbm", sxbm);
			if ("rqssgd".equals(templateCode)) {//设施改动
				YwRqSsgdSqbForm form = ywRqSsgdSqbService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getYwlxr();
				lxdh = form.getYwlxrtel();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.rqssgd(form,thisNoteActivityName,thisInstance.getActivityChineseName(), nextNoteActivityName, masterEntityKey, instance, 
						loginUserName, dpm, durationExpression, localResource,acceptTime,map);	
			}else if ("rqrsqjazwxqyzz".equals(templateCode)) {//企业资质
				YwRqQyzzInfoForm form = ywRqQyzzInfoService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getYwlxr();
				lxdh = form.getYwlxrtel();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.rqrsqjazwxqyzz(form,thisNoteActivityName,thisInstance.getActivityChineseName(), nextNoteActivityName, 
						masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if("hwggshsqb".equals(templateCode)){//户外广告	
				YwHwShSqbForm form = ywHwShSqbService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getYwlxr();
				lxdh = form.getYwlxrtel();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.hwggshsqb(form,thisNoteActivityName,thisInstance.getActivityChineseName(),
						nextNoteActivityName, masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if(templateCode.contains("rqjyxkz")){		//经营许可--管道和瓶装	
				YwRqQyjyxkForm form = ywRqQyjyxkService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getYwlxr();
				lxdh = form.getYwlxrtel();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.rqjyxkz(form,thisNoteActivityName,thisInstance.getActivityChineseName(), 
						nextNoteActivityName, masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if("csdllszysp".equals(templateCode)){//城市道路人行道及相关公共场地临时占用审批 
				DlzyForm form = ywDlzyService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getLxr();
				lxdh = form.getSqdwTel();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.csdllszysp(form,thisNoteActivityName,thisInstance.getActivityChineseName(),
						nextNoteActivityName, masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);				
			}else if("csdlwj".equals(templateCode)){//城市道路挖掘
				CsdlwjForm form = ywCsdlwjService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getLxr();
				lxdh = form.getJsdwTel();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.csdlwj(form,thisNoteActivityName,thisInstance.getActivityChineseName(), 
						nextNoteActivityName, masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);					
			}else if("ccgbggcs".equals(templateCode)){//拆除、关闭公厕许可
				GgcsForm form = ywGgcsServices.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getSqdw();
				lxdh = form.getSqrTel();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.ccgbggcs(form,thisNoteActivityName,thisInstance.getActivityChineseName(), nextNoteActivityName,
						masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if("shljqssj".equals(templateCode)){//从事陆域城市生活垃圾经营性清扫、收集、运输服务许可审批
				ShljqsForm form = ywShljqsService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getFrdb();
				lxdh = form.getLxdh();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.shljqssj(form,thisNoteActivityName,thisInstance.getActivityChineseName(), 
						nextNoteActivityName, masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if("shljys".equals(templateCode)){//从事水域城市生活垃圾经营性清扫、收集、运输服务许可审批
				ShljYsForm form = shljYsService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getFrdb();
				lxdh = form.getLxdh();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.shljys(form,thisNoteActivityName,thisInstance.getActivityChineseName(), nextNoteActivityName, 
						masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if("shljcz".equals(templateCode)){//从事城市生活垃圾经营性处置服务许可审批
				CsshljCzForm form = csshljCzService.get(Long.valueOf(masterEntityKey));
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getFrdb();
				lxdh = form.getLxdh();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.csshljcz(form,thisNoteActivityName,thisInstance.getActivityChineseName(), nextNoteActivityName,
						masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if(templateCode.contains("jzfqwczzpf")){//余泥处 排放  新增、变更、延期
				YwYnJzfqwczzPfsnForm form = null;
				if("jzfqwczzpf_xz".equals(templateCode)){
					form = ywYnJzfqwczzPfsnService.get(Long.valueOf(masterEntityKey));
				}else if("jzfqwczzpf_bg".equals(templateCode)){
					form = ywYnJzfqwczzPfsnbgService.get(Long.valueOf(masterEntityKey));
				}else{
					form = ywYnJzfqwczzPfsnyqService.get(Long.valueOf(masterEntityKey));
				}
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getJsdwLxr();
				lxdh = form.getJsdwLxrLxdh();
				wstjsj = form.getWstjsj();
				sendNotice = form.getSendNotice();
				form.setSxbm(sxbm);
				this.jzfqwczzpf(form,thisNoteActivityName,thisInstance.getActivityChineseName(), nextNoteActivityName,
						masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if(templateCode.contains("jzfqwczzxn")){//余泥处 消纳  新增、变更、延期
				YwYnJzfqwczzXnForm form = null;
				if("jzfqwczzxn_xz".equals(templateCode)){
					form = ywYnJzfqwczzXnService.get(Long.valueOf(masterEntityKey));
				}else if("jzfqwczzxn_bg".equals(templateCode)){
					form = ywYnJzfqwczzXnbgService.get(Long.valueOf(masterEntityKey));
				}else{
					form = ywYnJzfqwczzXnyqService.get(Long.valueOf(masterEntityKey));
				}
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getJsdwLxr();
				lxdh = form.getJsdwLxrLxdh();
				wstjsj = form.getWstjsj();
				form.setSxbm(sxbm);
				this.jzfqwczzxn(form,thisNoteActivityName,thisInstance.getActivityChineseName(), nextNoteActivityName, 
						masterEntityKey, instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}else if(templateCode.contains("jzljczz")){//余泥处 建筑废弃物处置证(运输)==>  新增发证、年审续证、变更换证、损坏换证、遗失补办
				YwYnJzfqwczcJbxxForm form = null;
				if("jzljczz_ysbb".equals(templateCode)){
					form = ywYnJzfqwczcYsbbService.get(Long.valueOf(masterEntityKey));
				}else if("jzljczz_xzfz".equals(templateCode)){
					form = ywYnJzfqwczcJbxxService.get(Long.valueOf(masterEntityKey));
				}else if("jzljczz_shhz".equals(templateCode)){
					form = ywYnJzfqwczcShhzService.get(Long.valueOf(masterEntityKey));
				}else if("jzljczz_nsxz".equals(templateCode)){
					form = ywYnJzfqwczcNsxzService.get(Long.valueOf(masterEntityKey));
				}else{
					form = ywYnJzfqwczcBghzService.get(Long.valueOf(masterEntityKey));
				}
				serialNo = form.getAcceptNo();
				password = form.getPassword();
				cbyw = form.getCbyw();
				sqrhsqdw = form.getSqdw();
				lxr = form.getSqdw();
				lxdh = form.getYwlxrtel();
				wstjsj = form.getWstjsj();
				form.setSxbm(sxbm);
				this.jzljczz(form,thisNoteActivityName,thisInstance.getActivityChineseName(), nextNoteActivityName, masterEntityKey,
						instance, loginUserName, dpm, durationExpression, localResource,acceptTime,map);
			}
			
			try{
				//保存延期开始
//				if(("jbrsl".equals(thisNoteActivityName) || "jbrcs".equals(thisNoteActivityName)) && ("czgldyqsh".equals(nextNoteActivityName) || "cldyqsh".equals(nextNoteActivityName)) && StringUtils.isNotBlank(sxbm)){
				if("jbrslyqbl".equals(nextNoteActivityName)){
				if(StringUtils.isNotBlank(sxbm)){
					WfUtilsEX.tbcxStart(serialNo, password, sxbm, masterEntityKey, loginUserName,templateCode,ywZhengwuInfoService,ywSphjInfoService,wfServiceEX,map,null);
				}				 
				 //修改答复的时间
				 this.updateDfsj(serialNo, map, templateCode, durationExpression, masterEntityKey);
				}
				//保存延期结束
				
				//保存补交受理
				if(StringUtils.isNotBlank(sxbm)){
					this.saveBjsl(user, instance.getProcInstId(), taskInstDbid, templateCode, masterEntityKey, sxbm, durationExpression);
				}				
			}catch(RuntimeException e){
				logger.info(serialNo+"-保存延期开始异常-");
				logger.error("保存延期开始异常"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
			}
			
			//网上申报
			if("cksa".equals(thisNoteActivityName) && StringUtils.isNotBlank(sendNotice) && sendNotice.equals("Y") && StringUtils.isNotBlank(sxbm)){
				WfUtilsEX.wssb(serialNo, password, sxbm, masterEntityKey, templateCode, cbyw, sqrhsqdw,lxr, lxdh, wstjsj, ywZhengwuInfoService, ywSphjInfoService);
			}
			
		}  
		
	
	}
	
	
	
	/**
	 * 修改答复时间
	 * @param serialNo 受理号
	 * @param map
	 * @param templateCode 业务编码
	 * @param durationExpression 审批天数
	 * @param masterEntityKey 业务表单id
	 */
	private void updateDfsj(String serialNo,Map<String,String> map,String templateCode,
			String durationExpression,String masterEntityKey){
		//修改答复的时间
		int yqts = wfServiceEX.getBusNum1(serialNo);
		if (yqts==0){
			//如果工作流里面没有延期就从其他主表里面取
			if(map.get("yqts")!=null)
			yqts=Integer.valueOf((String)map.get("yqts"));
		}
		//查询收案时间和结案时间
		String hql=" select proc from WfBusInstance inst,Jbpm4HistProcinst proc ,WfBusTemplate template where inst.procInstId=proc.procInstId " +
				" and inst.masterEntityKey='"+masterEntityKey+"' and inst.templateId=template.id and template.templateCode='"+templateCode+"'";
		List list=jbpm4HistProcinstDao.find(hql);
		String[] days=durationExpression.split(" ");
		if(days.length>0){
			yqts+=Integer.valueOf(days[0]);
		}
		if(yqts > 0){
			Jbpm4HistProcinst proc=(Jbpm4HistProcinst) list.get(0);
			Date startDate=proc.getStart();
			Date newDate=wfServiceEX.calculateDueDate(startDate,yqts);
			proc.setProcessDuedate(newDate);
			jbpm4HistProcinstDao.save(proc);//更新工作流日期
			if("ccgbggcs".equals(templateCode)){//设施改动时间
				GgcsForm form=ywGgcsServices.get(Long.valueOf(masterEntityKey));
				ywGgcsServices.updateDfsj(form);
			}
		}
	}
	
	
	
	/**
	 * 设施改动    数据交换
	 * @param form
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void rqssgd(YwRqSsgdSqbForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwRqSsgdSqbForFx ywRqSsgdSqbForFx = new  YwRqSsgdSqbForFx();
			YwRqSsgdSqbConvertor.convertFormToYwRqSsgdSqbForFx(form, ywRqSsgdSqbForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwRqSsgdSqbForFx(ywRqSsgdSqbForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue,"04_YW_RQ_SSGD_SQB");
				//设置ysl字段为3
				ywRqSsgdSqbService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
		if("cfgldsh".equals(nextNoteActivityName) || "czgldyqsh".equals(nextNoteActivityName)){//经办人受理环节，窗口可以打印受理通知书
			ywRqSsgdSqbService.changeSendAcceptNotice(Long.valueOf(masterEntityKey));
		}else if("wzgldyqsh".equals(thisNoteActivityName)){//委主管领导延期审核环节，窗口可以打印延期办理结果通知书
			ywRqSsgdSqbService.changeSendYqNotice(Long.valueOf(masterEntityKey));
		}
		
        //是否延期办理
        if ((form.getIsycbl()==null||"".equals(form.getIsycbl()))&&"czgldyqsh".equals(instance.getDestActivityName())) {
        	ywRqSsgdSqbService.changeIsycbl(Long.valueOf(masterEntityKey), "1");
        }
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	ywRqSsgdSqbService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
		ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqrq(), form.getAcceptNo(), form.getCbyw(), form.getYwlxr(), form.getSjr(), form.getSqdw(), 
				form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
		
		//政务中心 ---- 开始
		boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办		
		ywSphjInfoService.commonZwBeginByCksa(0, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, loginUserName, dpm, 
					durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());
		//政务中心 ---- 结束
	}
	
	
	/**
	 * 企业资质    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void rqrsqjazwxqyzz(YwRqQyzzInfoForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwRqQyzzInfoForFx ywRqQyzzInfoForFx = new  YwRqQyzzInfoForFx();
			YwRqQyzzInfoConvertor.convertFormToYwRqQyzzInfoForFx(form, ywRqQyzzInfoForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwRqQyzzInfoForFx(ywRqQyzzInfoForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_RQ_QYZZ_INFO");
				ywRqQyzzInfoService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);
				//设置ysl字段为3
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
		
		if("czgldsh".equals(nextNoteActivityName) || "czgldyqsh".equals(nextNoteActivityName)){//经办人受理环节，窗口可以打印受理通知书
			ywRqQyzzInfoService.changeSendAcceptNotice(Long.valueOf(masterEntityKey));
		}else if("wzgldyqsh".equals(thisNoteActivityName)){//委主管领导延期审核环节，窗口可以打印延期办理结果通知书
			ywRqQyzzInfoService.changeSendYqNotice(Long.valueOf(masterEntityKey));
		}
						
        //是否延期办理
        if ((form.getIsycbl()==null||"".equals(form.getIsycbl()))&&"czgldyqsh".equals(instance.getDestActivityName())) {
        	ywRqQyzzInfoService.changeIsycbl(Long.valueOf(masterEntityKey), "1");
        }
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	ywRqQyzzInfoService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getIeiDate(), form.getAcceptNo(), form.getCbyw(), form.getYwlxr(), form.getSjr(), form.getSqdw(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
		
		//政务中心 -- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(1, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());	
		//政务中心结束
	}
	
	
	/**
	 * 户外广告    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void hwggshsqb(YwHwShSqbForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwHwShSqbForFx ywHwShSqbForFx = new  YwHwShSqbForFx();
			YwHwShSqbConvertor.convertFormToYwHwShSqbForFx(form, ywHwShSqbForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwHwShSqbForFx(ywHwShSqbForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_HW_SH_SQB");
				ywHwShSqbService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);
				//设置ysl字段为3
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
		if("jbrxckcbl".equals(nextNoteActivityName)){//设置案件为咨询服务案件，户外广告特有的
			ywHwShSqbService.changeIsZxfwaj(Long.valueOf(masterEntityKey));
		}
		if("czgldsh".equals(nextNoteActivityName) || "czgldyqsh".equals(nextNoteActivityName) || "cfgldsh".equals(nextNoteActivityName)){//经办人受理环节，窗口可以打印受理通知书
			ywHwShSqbService.changeSendAcceptNotice(Long.valueOf(masterEntityKey));
		}else if("wzgldyqsh".equals(thisNoteActivityName)){//委主管领导延期审核环节，窗口可以打印延期办理结果通知书
			ywHwShSqbService.changeSendYqNotice(Long.valueOf(masterEntityKey));
		}
						
        //是否延期办理
        if ((form.getIsycbl()==null||"".equals(form.getIsycbl()))&&"czgldyqsh".equals(instance.getDestActivityName())) {
        	ywHwShSqbService.changeIsycbl(Long.valueOf(masterEntityKey), "1");
        }
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	ywHwShSqbService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqrq(), form.getAcceptNo(), form.getCbyw(), form.getFrxm(), form.getSjr(), form.getSqdw(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);

		//政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(2, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());		
		//政务中心 --- 结束
		
	}
	
	
	/**
	 * 经营许可--管道和瓶装    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void rqjyxkz(YwRqQyjyxkForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwRqQyjyxkForFx ywRqQyjyxkForFx = new  YwRqQyjyxkForFx();
			YwRqQyjyxkConvertor.convertFormToYwRqQyjyxkForFx(form, ywRqQyjyxkForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwRqQyjyxkForFx(ywRqQyjyxkForFx);//设置unitValue
				if("rqjyxkz_gdqy".endsWith(instance.getTemplateCode())){
					object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_RQ_JYXK_GD");
				}else{
					object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_RQ_JYXK_PZ");
				}
				ywRqQyjyxkService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);
				//设置ysl字段为3
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
		if("czgldsh".equals(nextNoteActivityName) || "czgldyqsh".equals(nextNoteActivityName)){//经办人受理环节，窗口可以打印受理通知书
			ywRqQyjyxkService.changeSendAcceptNotice(Long.valueOf(masterEntityKey));
		}else if("wzgldyqsh".equals(thisNoteActivityName)){//委主管领导延期审核环节，窗口可以打印延期办理结果通知书
			ywRqQyjyxkService.changeSendYqNotice(Long.valueOf(masterEntityKey));
		}
			
        //是否延期办理
        if ((form.getIsycbl()==null||"".equals(form.getIsycbl()))&&"czgldyqsh".equals(instance.getDestActivityName())) {
        	ywRqQyjyxkService.changeIsycbl(Long.valueOf(masterEntityKey), "1");
        }
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	ywRqQyjyxkService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqrq(), form.getAcceptNo(), form.getCbyw(), form.getLxr(), form.getSjr(), form.getSqdw(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
		
		//政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(3, form, "rqjyxkz", thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());	
		//政务中心 --- 结束
	}
	
	/**
	 * 城市道路人行道及相关公共场地临时占用审批    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void csdllszysp(DlzyForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwSrDlzyForFx ywSrDlzyForFx = new  YwSrDlzyForFx();
			YwSrDlzyConvertor.convertFormToYwSrDlzyForFx(form, ywSrDlzyForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwSrDlzyForFx(ywSrDlzyForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_SR_CSDL_LSZY");
				ywDlzyService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);
				//设置ysl字段为3
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
    	
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	ywDlzyService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getTbrq(), form.getAcceptNo(), form.getCbyw(), form.getLxr(), form.getSjr(), form.getSqdw(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
        
		//政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(4, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());	
		//政务中心 --- 结束
	}
	
	
	/**
	 * 城市道路挖掘    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void csdlwj(CsdlwjForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		//城市道路挖掘
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwSrCsdlwjForFx ywSrCsdlwjForFx = new  YwSrCsdlwjForFx();
			YwSrCsdlwjConvertor.convertFormToYwSrCsdlwjForFx(form, ywSrCsdlwjForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwSrCsdlwjForFx(ywSrCsdlwjForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_SR_CSDL_WJ");
				ywCsdlwjService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);//设置ysl字段为3				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
    	
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	ywCsdlwjService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getTbrq(), form.getAcceptNo(), form.getCbyw(), form.getLxr(), form.getSjr(), form.getJsdw(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
		
		//政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(5, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());
		//政务中心 --- 结束
	}
	
	/**
	 * 拆除、关闭公厕许可    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void ccgbggcs(GgcsForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwGgcsForFx ywGgcsForFx = new  YwGgcsForFx();
			YwSrGgcsConvertor.convertFormToYwGgcsForFx(form, ywGgcsForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwGgcsForFx(ywGgcsForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_SS_CG_GC");
				ywGgcsServices.changeYslState(Long.valueOf(masterEntityKey), 3l,null);//设置ysl字段为3				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
		
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	ywGgcsServices.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqrq(), form.getAcceptNo(), form.getCbyw(), form.getSqdw(), form.getSjr(), form.getSqdw(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
        
		//政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(6, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());	
		//政务中心 --- 结束
	}
	
	/**
	 * 从事陆域城市生活垃圾经营性清扫、收集、运输服务许可审批    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void shljqssj(ShljqsForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{

		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwHwShljqsForFx ywHwShljqsForFx = new  YwHwShljqsForFx();
			YwHwShljqsConvertor.convertFormToYwHwShljqsForFx(form, ywHwShljqsForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwHwShljqsForFx(ywHwShljqsForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_HW_LCSLJ_JYFW");
				smartFormShljqsService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);//设置ysl字段为3				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
    	
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	ywShljqsService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getTbrq(), form.getAcceptNo(), form.getCbyw(), form.getFrdb(), form.getSjr(), form.getQymc(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);

        //政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(7, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());
		//政务中心 --- 结束
	}
	
	/**
	 * 从事水域城市生活垃圾经营性清扫、收集、运输服务许可审批    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void shljys(ShljYsForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{

		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			ShljYsForFx shljYsForFx = new  ShljYsForFx();
			YwHwShljysConvertor.convertFormToShljYsForFx(form, shljYsForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setShljYsForFx(shljYsForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_HW_SCSLJ_JYFW");
				shljYsService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);//设置ysl字段为3				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
		
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	shljYsService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getSlrq(), form.getAcceptNo(), form.getCbyw(), form.getFrdb(), form.getSjr(), form.getQymc(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
        
		//政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(8, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());
		//政务中心 --- 结束
	}
	
	/**
	 * 从事城市生活垃圾经营性处置服务许可审批    数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void csshljcz(CsshljCzForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{

		String qybh = csshljCzService.getQyidByAcceptNo(form.getAcceptNo());
		form.setQybh(qybh);
		System.out.println("qybh---------------------------------"+qybh);
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			CsshljczForFx csshljczForFx = new  CsshljczForFx();
			YwHwCzConvertor.convertFormToCsshljczForFx(form, csshljczForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setCsshljczForFx(csshljczForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_CS_LJ_CZ");
				csshljCzService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);//设置ysl字段为3				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
		
        //设置结案时间
        if(instance.getDestActivityName().contains("end")){
        	csshljCzService.endSave(Long.valueOf(masterEntityKey));
        }
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqrq(), form.getAcceptNo(), form.getCbyw(), form.getFrdb(), form.getSjr(), form.getQymc(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
        
        //政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(9, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());
		//政务中心 --- 结束
	}
	
	/**
	 * 建筑废弃物处置证(排放)  新增、变更、延期      数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void jzfqwczzpf(YwYnJzfqwczzPfsnForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{

		//建筑废弃物处置证(排放)
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwYnJzfqwczzPfsnForFx ywYnJzfqwczzPfsnForFx = new  YwYnJzfqwczzPfsnForFx();
			YwYnJzfqwczzPfsnConvert.convertFormToYwYnJzfqwczzPfsnForFx(form, ywYnJzfqwczzPfsnForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwYnJzfqwczzPfsnForFx(ywYnJzfqwczzPfsnForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_YNC_JZ_FQ_PS");
				ywYnJzfqwczzPfsnService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);//设置ysl字段为3				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束
    	
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqDate(), form.getAcceptNo(), form.getCbyw(), form.getJsdwLxr(), form.getSjr(), form.getSqdw(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
        
        //政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(12, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());	
		//政务中心 --- 结束
	}
	
	/**
	 * 建筑废弃物处置证(排放)  新增、变更、延期      数据交换
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void jzfqwczzxn(YwYnJzfqwczzXnForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwYnJzfqwczzXnForFx ywYnJzfqwczzXnForFx = new  YwYnJzfqwczzXnForFx();
			YwYnJzfqwczzXnConvert.convertFormToYwYnJzfqwczzXnForFx(form, ywYnJzfqwczzXnForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwYnJzfqwczzXnForFx(ywYnJzfqwczzXnForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, "04_YW_YNC_JZ_FQ_XN");
				ywYnJzfqwczzXnService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);//设置ysl字段为3				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束				
		
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
        //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
        ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqDate(), form.getAcceptNo(), form.getCbyw(), form.getJsdwLxr(), form.getSjr(), form.getSqdw(), 
        		form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
        
        //政务中心 --- 开始
        boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(13, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());	
		//政务中心 --- 结束
	}
	
	/**
	 * 余泥处 建筑废弃物处置证(运输)==>  新增发证、年审续证、变更换证、损坏换证、遗失补办
	 * @param thisNoteActivityName
	 * @param nextNoteActivityName
	 * @param masterEntityKey
	 * @param instance
	 * @param loginUserName
	 * @param dpm
	 * @param date
	 * @param ywMtbjlshInfoid
	 * @param durationExpression
	 * @param localResource
	 */
	public void jzljczz(YwYnJzfqwczcJbxxForm form,String thisNoteActivityName,String thisNoteActivityChineseName,String nextNoteActivityName,String masterEntityKey,
			WfBusInstanceTaskForm instance,String loginUserName,String dpm,String durationExpression,
			ResourceBundle localResource,Date acceptTime,Map<String,String> map) throws Exception{
		boolean flag = false;//如果是我们系统收的案，而且是窗口收案环节，则为true
		//把系统的数据交换到方欣那边  开始
		if(form.getAcceptNo().length()>13 && form.getYsl() == null && StringUtils.isBlank(form.getSendNotice())){
			flag = true;
			YwYnJzfqwczcJbxxForFx ywYnJzfqwczcJbxxForFx = new  YwYnJzfqwczcJbxxForFx();
			YwYnJzfqwczcJbxxConvertor.convertFormToYwYnJzfqwczcJbxxForFx(form, ywYnJzfqwczcJbxxForFx);
			try {
				Object2XML object2XML = new Object2XML();
				UnitValue unitValue = new UnitValue();
				unitValue.setYwYnJzfqwczcJbxxForFx(ywYnJzfqwczcJbxxForFx);//设置unitValue
				object2XML.orderCancel(form.getAcceptNo(),localResource,unitValue, getJzljczzBusinessCode(instance.getTemplateCode()));
				ywYnJzfqwczcJbxxService.changeYslState(Long.valueOf(masterEntityKey), 3l,null);//设置ysl字段为3
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//把系统的数据交换到方欣那边  结束				
		
        //GIS
        this.gisClosecase(instance, form.getAcceptNo());
        
      //把审批状态数据保存到ywWebserviceInfo ，交换给方欣
		ywWebserviceInfoService.saveYwWebserviceInfo(form.getSqDate(), form.getAcceptNo(), form.getCbyw(), form.getYwlxr(), form.getSjr(), form.getSqdw(), 
				form.getBusinessCode(), form.getApprovalNo(), loginUserName, dpm, thisNoteActivityName, acceptTime, flag, thisNoteActivityChineseName, instance);
		
        //政务中心 --- 开始
		boolean iswb = "Y".equals(form.getSendNotice())?true:false;//是否网办
		ywSphjInfoService.commonZwBeginByCksa(14, form, instance.getTemplateCode(), thisNoteActivityName, nextNoteActivityName, masterEntityKey, instance, 
					loginUserName, dpm, durationExpression, localResource, sprzwdm, sprzwmc, iswb,map,form.getSxbm());		
		//政务中心 --- 结束
	}
	
	/**
	 * 获取 余泥处 建筑废弃物处置证(运输)的businessCode
	 * @param templateCode
	 * @return
	 */
	public String getJzljczzBusinessCode(String templateCode){
		String businessCode = "";
		if("jzljczz_ysbb".equals(templateCode)){
			businessCode = "04_YW_YNC_JZ_FQ_YS_YSBB";
		}else if("jzljczz_xzfz".equals(templateCode)){
			businessCode = "04_YW_YNC_JZ_FQ_YS_XZFZ";
		}else if("jzljczz_shhz".equals(templateCode)){
			businessCode = "04_YW_YNC_JZ_FQ_YS_SHHZ";
		}else if("jzljczz_nsxz".equals(templateCode)){
			businessCode = "04_YW_YNC_JZ_FQ_YS_NSXZ";
		}else if("jzljczz_bghz".equals(templateCode)){
			businessCode = "04_YW_YNC_JZ_FQ_YS_BGHZ";
		}
		return businessCode;
	}
	
	/**
	 * 提前一天通知经办人
	 * @param taskInstDbid
	 * @return
	 */
	public void sendSmsInfo(Long taskInstDbid){
		Jbpm4HistTask jbpm4HistTask = null;
		try {
			jbpm4HistTask = jbpm4HistTaskDao.get(taskInstDbid);
			String procInstId = jbpm4HistTask.getProcInstId();
			Jbpm4HistTask jbpm4HistTask2 = null;
			if(StringUtils.isNotBlank(procInstId) && procInstId.contains("hwgg")){//户外广告才发短信提醒
				jbpm4HistTask2 = jbpm4HistTaskDaoEX.getHistTasksByProcInstIdAndState(procInstId);
			}
						
			if(jbpm4HistTask2 != null && jbpm4HistTask2.getDuedate() !=null){
				YwComFsxx ywComFsxx = ywComFsxxService.getYwComFsxxByProcInstId(procInstId);
				if(ywComFsxx == null){
					ywComFsxx = new YwComFsxx();
				}
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(jbpm4HistTask2.getDuedate());
				calendar.add(Calendar.DATE, -1);
				String preDate = DateUtils.dateTimeToString(calendar.getTime(), "yyyyMMdd");//获得前一天
				String assignee = jbpm4HistTask2.getAssignee();
				OmUserForm omUserForm = omUserService.get(assignee);
				ywComFsxx.setMoblie(omUserForm.getMobile());//发送手机
				ywComFsxx.setProcInstId(procInstId);
//				ywComFsxx.setSendDate(new Date());
				ywComFsxx.setSendTime(preDate);//前一天
				ywComFsxx.setIsSend(null);
				ywComFsxx.setAssignee(assignee);
				ywComFsxxService.saveOrUpdateYwComFsxx(ywComFsxx);
			}else{
				System.out.println("没有信息要发送---------------------");
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
	}
	
	public void getLdClass(String thisNoteActivityName){
		if(thisNoteActivityName.equals("cksa")){
			sprzwdm = "0001";
			sprzwmc = "办事员";
		}else if(thisNoteActivityName.equals("jbrsl") ||thisNoteActivityName.equals("jbrcs")){
			sprzwdm = "0002";
			sprzwmc = "科员" ;
		}else if(thisNoteActivityName.equals("cfgldsh")){
			sprzwdm = "0008";
			sprzwmc = "副处长";
		}else if(thisNoteActivityName.equals("czgldsh") || thisNoteActivityName.equals("czsp") || "czyj".equals(thisNoteActivityName)){
			sprzwdm = "0007";
			sprzwmc = "处长";
		}else if(thisNoteActivityName.equals("wfgldsh") ||"wfgldsp".equals(thisNoteActivityName)){
			sprzwdm = "0015";
			sprzwmc = "副主任";
		}else if(thisNoteActivityName.equals("wzgldsp")){
			sprzwdm = "0013";
			sprzwmc = "主任" ;
		}else if(thisNoteActivityName.equals("jbrsj")||thisNoteActivityName.equals("jbrbj")){
			sprzwdm = "0002";
			sprzwmc = "科员" ;
		}else if(thisNoteActivityName.equals("dzgz")){
			sprzwdm = "0001";
			sprzwmc = "办事员";
		}
	
	}
	/**
	 * 获取受理时间
	 * @param task
	 * @return
	 */
	public Date getAcceptTime(Jbpm4HistTask thisInstance){
		String sql = "select jha.END_ from JBPM4_HIST_ACTINST jha where jha.ACTIVITY_NAME_='cksa' and jha.EXECUTION_='"+thisInstance.getExecution()+"'";
		SQLQuery query = jbpm4HistTaskDao.getSession().createSQLQuery(sql);
		List list = query.list();
		if(list != null && list.size() > 0){
			Timestamp timestamp = (Timestamp)list.get(0);
			System.out.println("timestamp = "+ timestamp);
			Date date = new java.util.Date(timestamp.getTime());;
			System.out.println("timestamp.getDate() = "+ date);
//			timestamp = 2012-04-11 16:46:31.671
//			timestamp.getDate() = Wed Apr 11 16:46:31 CST 2012
			return date;
		}
		return null;
	}
	
	/**
	 * 改变地图案件状态
	 * @param instance  
	 * @param acceptNo  受理号
	 */
	public void gisClosecase(WfBusInstanceTaskForm instance,String acceptNo){
		try{
			if (instance.getDestActivityName().contains("end")) {
				YwClosecase ywClosecase=new YwClosecase();
	        	ywClosecase.setAcceptNo(acceptNo);
	        	ywClosecase.setCasetype(instance.getTemplateCode());
	        	ywClosecaseService.saveEntity(ywClosecase);
			}
		}catch(Exception e){
			System.out.println("修改GIS案件状态出错-------------------------");
		}
	}



	/*
	 * 保存补交受理(non-Javadoc)
	 * @see com.augurit.gzcgwsp.sendNotice.service.IExchangeStateService#saveBjsl(com.augurit.common.system.web.auth.form.LoginUserForm, com.augurit.wf.bi.web.form.WfBusInstanceTaskForm)
	 */
	@Override
	public boolean saveBjsl(LoginUserForm user, String procInstId,Long taskInstDbid,String templateCode,String masterEntityKey,String sxbm,String durationExpression) {
		try {
			Map<String,String> map=this.buildMap(user, taskInstDbid, masterEntityKey, templateCode, true);
			if(map!=null){
				map.put("sxbm", sxbm);
				boolean flag=true;
				if(StringUtils.isNotBlank(templateCode) && !templateCode.contains("qx")){
					 flag=ywZhengwuInfoService.saveBjsl(map);
				}				
				System.out.println("saveFlag = "+flag);
			    String bjslsj=map.get("bjslsj");
		    	if(StringUtils.isNotBlank(bjslsj)){
		    		System.out.println("bjslsj = "+bjslsj);
		    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		    		Date bjslDate = sdf.parse(bjslsj);
		    		int days =  Integer.parseInt(durationExpression.split(" ")[0]);
		        	String sql = "from Jbpm4HistProcinst t where t.procInstId='"+procInstId+"'";
		    		List list=jbpm4HistProcinstDao.find(sql);
		    		if(list.size()>0){
			    		Jbpm4HistProcinst proc=(Jbpm4HistProcinst) list.get(0);
			    		Date newDate=wfServiceEX.calculateDueDate(bjslDate,days);
			    		proc.setProcessDuedate(newDate);
			    		jbpm4HistTaskDao.getSession().update(proc);
		    		}
		    	}				
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 
	 * @param templateCode 业务模板
	 * @param masterEntityKey 主键id
	 * @return
	 */
	public  Map<String,String> getMapByTemplate(String templateCode,String masterEntityKey){
		Locale locale = Locale.getDefault(); 
		ResourceBundle localResource = ResourceBundle.getBundle("interfaceExchange", locale); 
		String sxbm = wfServiceEX.getPropertiesValueByKey(localResource, templateCode);
		Object form=null;
		if (templateCode.contains("rqssgd")) {//设施改动
			form = ywRqSsgdSqbService.get(Long.valueOf(masterEntityKey));
		}else if (templateCode.contains("rqrsqjazwxqyzz")) {//企业资质
			form = ywRqQyzzInfoService.get(Long.valueOf(masterEntityKey));
		}else if("hwggshsqb".equals(templateCode)){//户外广告	
			form = ywHwShSqbService.get(Long.valueOf(masterEntityKey));
		}else if(templateCode.contains("rqjyxkz")){		//经营许可--管道和瓶装	
			form = ywRqQyjyxkService.get(Long.valueOf(masterEntityKey));			
		}else if(templateCode.contains("csdllszysp")){//城市道路人行道及相关公共场地临时占用审批 
			form = ywDlzyService.get(Long.valueOf(masterEntityKey));
		}else if(templateCode.contains("csdlwj")){//城市道路挖掘
			form = ywCsdlwjService.get(Long.valueOf(masterEntityKey));
		}else if("ccgbggcs".equals(templateCode)){//拆除、关闭公厕许可
			form = ywGgcsServices.get(Long.valueOf(masterEntityKey));
		}else if("shljqssj".equals(templateCode)){//从事陆域城市生活垃圾经营性清扫、收集、运输服务许可审批
			form = ywShljqsService.get(Long.valueOf(masterEntityKey));
		}else if("shljys".equals(templateCode)){//从事水域城市生活垃圾经营性清扫、收集、运输服务许可审批
			form = shljYsService.get(Long.valueOf(masterEntityKey));
		}else if("shljcz".equals(templateCode)){//从事城市生活垃圾经营性处置服务许可审批
			form = csshljCzService.get(Long.valueOf(masterEntityKey));
		}else if(templateCode.contains("jzfqwczzpf")){//余泥处 排放  新增、变更、延期
			if("jzfqwczzpf_xz".equals(templateCode)){
				form = ywYnJzfqwczzPfsnService.get(Long.valueOf(masterEntityKey));
			}else if("jzfqwczzpf_bg".equals(templateCode)){
				form = ywYnJzfqwczzPfsnbgService.get(Long.valueOf(masterEntityKey));
			}else{
				form = ywYnJzfqwczzPfsnyqService.get(Long.valueOf(masterEntityKey));
			}
		}else if(templateCode.contains("jzfqwczzxn")){//余泥处 消纳  新增、变更、延期
			if("jzfqwczzxn_xz".equals(templateCode)){
				form = ywYnJzfqwczzXnService.get(Long.valueOf(masterEntityKey));
			}else if("jzfqwczzxn_bg".equals(templateCode)){
				form = ywYnJzfqwczzXnbgService.get(Long.valueOf(masterEntityKey));
			}else{
				form = ywYnJzfqwczzXnyqService.get(Long.valueOf(masterEntityKey));
			}
		}else if(templateCode.contains("jzljczz")){//余泥处 建筑废弃物处置证(运输)==>  新增发证、年审续证、变更换证、损坏换证、遗失补办
			if("jzljczz_ysbb".equals(templateCode)){
				form = ywYnJzfqwczcYsbbService.get(Long.valueOf(masterEntityKey));
			}else if("jzljczz_xzfz".equals(templateCode)){
				form = ywYnJzfqwczcJbxxService.get(Long.valueOf(masterEntityKey));
			}else if("jzljczz_shhz".equals(templateCode)){
				form = ywYnJzfqwczcShhzService.get(Long.valueOf(masterEntityKey));
			}else if("jzljczz_nsxz".equals(templateCode)){
				form = ywYnJzfqwczcNsxzService.get(Long.valueOf(masterEntityKey));
			}else{
				form = ywYnJzfqwczcBghzService.get(Long.valueOf(masterEntityKey));
			}
		}
		//开始补交受理
		if(form!=null){
			Map<String,String> map=WfUtilsEX.buildMap(form,"yyyy年MM月dd日");
			map.put("sxbm", sxbm);
			return map;
		}else{
			return null;
		}
		
		
				
	}
	
	/**
	 * 延期理由
	 * @param templdateCode
	 * @param ywId
	 * @return
	 */
	private String getYqly(String templateCode,Jbpm4HistTask taskInst){
		String opionion="";
		if("hwggshsqb".equals(templateCode)){
			opionion=this.getYqOpinion("'jbrsl'", taskInst);
		}else{
			opionion=this.getYqOpinion("'jbrsl','jbrcs'", taskInst);
		}
		return opionion;
	}

	/**
     *获取某个环节的意见
     * @param activeName
     * @return
     */
    private  String getYqOpinion(String activeName,Jbpm4HistTask taskInstance){
    	String execution=taskInstance.getExecution();
    	List<Jbpm4HistTask> list = wfServiceEX.contentByTaskId(execution,activeName);
		StringBuffer sb = new StringBuffer();
		if(list!=null && list.size()>0){
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
			 sb.append(list.get(i).getHandleComments());
			 break;
			}
		 }
		}
		return sb.toString();
    }
	/**
	 *
	 * 将表单内容转换为map
	 * @param user 当前用户
	 * @param instance 工作流表单
	 * @return
	 */
    public Map<String,String> buildMap(LoginUserForm user,Long taskInstDbid,String masterEntityKey,String templateCode,boolean isCheckActivityName){
    	Map<String,String> map = getMapByTemplate(templateCode, masterEntityKey);
    	if(map == null){
    		map = new HashMap<String,String>();
    	}
		String loginUserName = user.getUser().getUserName();
		String dpm = user.getOrg().getOrgName();
		//获得ID
		if(StringUtils.isBlank(masterEntityKey)){
			return null;
		}
		if(taskInstDbid != null){
			Jbpm4HistTask taskInstance = jbpm4HistTaskDao.get(taskInstDbid);//这个节点对象
			String actName = taskInstance.getActivityName();//环节名称
			if(isCheckActivityName){
				boolean flag = checkActivityName(actName,templateCode);
				if(!flag){
					return null;
				}
			}
			//延期理由
			String yqly = "";
			if(taskInstDbid != null){
				yqly = getYqly(templateCode, taskInstance);
			}		
			map.put("yqly", yqly);//延期理由
		}	
		
		map.put("username", loginUserName);
		map.put("formId", masterEntityKey);
		map.put("dpm", dpm);
		
		return  map;
	}



	/**
	 * 检查环节名称（是否是经办人受理环节）
	 * @param actName 环节名称
	 * @param templateCode 工作流模板名称
	 * @return
	 */
	private boolean checkActivityName(String actName, String templateCode) {
		boolean flag=false;
		if("ccgbggcs".equals(templateCode) && "jbrcs".equals(actName)){//设施
			flag=true;
		}else if(templateCode.contains("csdlwj") && "jbrcs".equals(actName)){//道路挖掘
			flag=true;
		}else if("shljcz".equals(templateCode) && "jbrcs".equals(actName)){//建筑废弃物
			flag=true;
		}else if("shljqssj".equals(templateCode) && "jbryskc".equals(actName)){//陆域
			flag=true;
		}else{
			if("jbrsl".equals(actName)){
				flag=true;
			}
		}
		return flag;
	}



	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.sendNotice.service.IExchangeStateService#saveBjgz(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public boolean saveBjgz(String templateCode,String ywId,String userName) {
		Map<String,String> map=this.getMapByTemplate(templateCode,ywId);
		String acceptNo=map.get("acceptNo");
		String password=map.get("password");
		String sxbm=map.get("sxbm");
		String bjgzqd=map.get("bjgzqd");
		String bjgzyj=map.get("bjgzyy");
		this.ywZhengwuInfoService.saveBjgz(acceptNo,password,sxbm,ywId,userName,bjgzyj,bjgzqd);
		return false;
	}
	
}
